<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<input type="text" id="input1"><br />
		数字内容:
		<input type="text" id="input2"><br />
		
		<script type="text/javascript">
			input1.onkeydown = function(e)
			{
				console.log("按下")
				console.log(e.key);
				console.log(e.keyCode);
			}
			input1.onkeyup = function(e)
			{
				console.log("抬起")
				console.log(e.key);
				console.log(e.keyCode);
			}
			input1.onkeypress = function(e)
			{
				console.log("按了")
				console.log(e.key);
				console.log(e.keyCode);
			}
			
			
			input2.onkeydown = function(e)
			{
				if(e.keyCode>=48 && e.keyCode<=57)
				{
					
				}
				else
				{
					console.log("不是数字");
					event.preventDefault();
				}
			}
			
		</script>
	</body>
</html>